package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.SystemFeedingProgramInsertRequestDTO;
import com.example.child_protection.dto.request.find.SystemFeedingProgramRequestDTO;
import com.example.child_protection.dto.request.update.SystemFeedingProgramContentUpdateRequestDTO;
import com.example.child_protection.dto.request.update.SystemFeedingProgramUpdateRequestDTO;
import com.example.child_protection.dto.response.SystemFeedingProgramListResponseDTO;
import com.example.child_protection.dto.response.SystemFeedingProgramResponseDTO;
import com.example.child_protection.service.SystemFeedingProgramManageService;
import com.example.child_protection.service.SystemFeedingProgramQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 喂养方案管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("systemFeedingProgram")
@Api(value = "/api-systemFeedingProgram", description = "喂养方案管理")
public class SystemFeedingProgramController extends BaseController {

    @Autowired
    public SystemFeedingProgramManageService systemFeedingProgramManageService;

    @Autowired
    public SystemFeedingProgramQueryService systemFeedingProgramQueryService;

    @ApiOperation(value ="查询喂养方案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemFeedingProgramResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        SystemFeedingProgramResponseDTO responseDTO = systemFeedingProgramQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询喂养方案列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemFeedingProgramListResponseDTO findList(SystemFeedingProgramRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        SystemFeedingProgramListResponseDTO responseDTO = systemFeedingProgramQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加喂养方案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(SystemFeedingProgramInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemFeedingProgramManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改喂养方案基本信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(SystemFeedingProgramUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemFeedingProgramManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改喂养方案文本内容和备注", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/updateContent", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO updateContent(SystemFeedingProgramContentUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemFeedingProgramManageService.updateContent(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除喂养方案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemFeedingProgramManageService.delete(requestDTO);
        return responseDTO;
    }

}
